
package ch.hearc.coursJava.kitBase.tableau.equationOrdre2;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.util.List;

import junit.framework.Assert;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import ch.hearc.coursJava.kitBase.tools.ContainerTools;

public class QuadraticEquationTest
	{

	/*------------------------------------------------------------------*\
	 |*							Constructeurs							*|
	 \*------------------------------------------------------------------*/

	@Before
	public void before()
		{
		// rien
		}

	@After
	public void after()
		{
		// rien
		}

	/*------------------------------------------------------------------*\
	 |*							Methodes Public							*|
	 \*-----------------------------------------------------------------*/

	@Test
	public void testQuadraticEquation()
		{
			//Test 1
			{
			double a = 1;
			double b = -3;
			double c = 2;
			double[] tabX = EquationOrdre2.solve(a, b, c);
			double x1 = 1;
			double x2 = 2;

			assertTrue(tabX.length == 2);
			assertTrue((tabX[0] == x1 && tabX[1] == x2) || (tabX[0] == x2 && tabX[1] == x1));
			}

			//Test 2
			{
			double a = 1;
			double b = -3;
			double c = 2;
			double[] tabX = EquationOrdre2.solve(a, b, c);
			double x1 = 1;
			double x2 = 2;

			List<Double> listeX = ContainerTools.toList(tabX);

			assertTrue(tabX.length == 2);
			assertTrue(listeX.contains(x1));
			assertTrue(listeX.contains(x2));
			}

			//Test 3
			{
			double a = 1;
			double b = -2;
			double c = 1;
			double[] tabX = EquationOrdre2.solve(a, b, c);
			double x1 = 1;

			assertTrue(tabX.length == 1);
			assertTrue(x1 == tabX[0]);
			}

			//Test 4
			{
			double a = 1;
			double b = 1;
			double c = 1;
			double[] tabX = EquationOrdre2.solve(a, b, c);

			assertTrue(tabX == null);
			Assert.assertTrue(tabX == null);
			assertTrue(null == tabX);
			Assert.assertFalse(tabX != null);
			assertFalse(tabX != null);
			Assert.assertNull(tabX);
			}

		}

	@Test
	public void testDiscriminant()
		{
		double a = 1;
		double b = -3;
		double c = 2;
		double[] tab=new double[]{a,b,c};
		double discriminant = EquationOrdre2.discriminant(tab);
		double discriminantTheorique = 1;
		Assert.assertTrue(discriminantTheorique == discriminant);
		}
	/*------------------------------------------------------------------*\
	|*							Methodes Private						*|
	\*------------------------------------------------------------------*/

	}
